#ifndef __TERMINAL_H
#define __TERMINAL_H

/*-------------------------------------------------------------------------
 * MPLAB-Cxx  PIC24FJ16GA002 processor header
 *
 * (c) Copyright 1999-2008 Microchip Technology, All rights reserved
 *-------------------------------------------------------------------------*/
#include "CommandProc.h"

#define PRODUCT_CATG_EXTEND		0
#define PRODUCT_CATG_NODE		1
#define PRODUCT_CATG_TERCNF		2
#define PRODUCT_CATG_UDISK		4
#define PRODUCT_CATG_HDISK		5
#define PRODUCT_CATG_NB			6

#define PRODUCT_COUNT			0 //count for the product 
#define PRODUCT_HW_VERSION		1<<14
#define	PRODUCT_SW_VERSION	0<<12
#define PRODUCT_SW_RELEASE		0<<10
#define PRODUCT_SW_BUILD		1<<8
#define PRODUCT_NUMBER			1	//change with every terminal device
#define PRODUCT_SERIAL_NO		PRODUCT_HW_VERSION |\
								PRODUCT_SW_VERSION |\
								PRODUCT_SW_RELEASE |\
								PRODUCT_SW_BUILD   |\
								PRODUCT_NUMBER							

#define TERMINAL_STATUS_OK			    0
#define TERMINAL_STATUS_MOVE            1
#define TERMINAL_STATUS_BATT            1<<1
#define TERMINAL_STATUS_BREAK           1<<2
#define TERMINAL_STATUS_CHARGE          1<<3

#define TERMINAL_POWER_0DB			1
#define TERMINAL_POWER_5DB			2
#define TERMINAL_POWER_10DB		3
#define TERMINAL_POWER_20DB		4





/* State of terminal run time */
typedef enum
{
    /*!state IDLE; keep number 0*/
    terminalStateIdle,
    /*!state Config; keep number 1*/
    terminalStateNormal,
    /*!state Abnormal*/
    terminalStateAbnormal,
    /*!number of terminal statemachine states*/
    terminalStateNumber
    /*!values for states of terminal statemachine*/
} terminalState_t;

typedef struct sproductSerialNo  //struct of product SerialNo
{
    UINT16 productSN; 		//16 bit of product Serial No
    union uProductCat    	//product category
    {
        UINT8 bproductCat;
        struct sproductCat
        {           
            UINT8 category:   6;
            UINT8 extend:     2;
        }sproductCat;
    }productCat;
    UINT8  productCount;
}T_productserialNo;

typedef struct sHWConfig	//hardware configurations
{
	struct sTimer1Config    //Timer1 configuration
        {
            UINT16 intConfig;	//Timer1 interrupt configuration
            UINT16 perConfig;   //Timer1 period configuration
        }Timer1Config;
        struct sTimer1Config Timer2Config; //Timer2 configuration
//	TODO: add other chip configuration here 
}T_HWConfig;
//

typedef struct sRuntimePara
{
    UINT32 Node_ID; //node id
    UINT32 Terminal_ID; //TERMINAL_ID
    UINT8 Terminal_Status; //terminal status
    UINT8 Terminal_Channel; //working channel
    UINT8 Terminal_Power; //transmit power
    UINT8 Terminal_RSSI; //RSSI--reserved
    UINT16 Terminal_Slot; //working slot
    UINT16 Terminal_Time; //Random time
    UINT8 lastState; //last State
    UINT8 currentState; //current State
    T_HWConfig HWConfig; //HW configuration
} T_RuntimePara;
//
typedef struct terminal
{
	UINT32		SerialNo;      	//SERIAL_NUMBER	
	T_RuntimePara	runtimePara;	//runtime parameters	
	T_ReqIndbuf	Reqbuf __attribute__ ((packed));//Requester need to send
	T_ReqIndbuf	Indbuf __attribute__ ((packed));//Indicator received
}T_terminal;

#endif  //__TERMINAL_H
